package com.well.menjin.service.impl;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.well.menjin.dao.IZoneDao;
import com.well.menjin.domain.Zone;
import com.well.menjin.model.Sort;
import com.well.menjin.model.ZoneOpt;
import com.well.menjin.service.IZoneService;
/**
 * 
* @ClassName: ZoneServiceImpl 
* @Description: 区域业务层实现类
* @author 姜俊健 
* @date 2016年6月13日 下午8:26:47 
*
 */
@Service
@Transactional
public class ZoneServiceImpl implements IZoneService {
	@Autowired
	private IZoneDao zonedao ;
	
	@Override
	public List<Zone> getZones(int start,int limit,int page,Sort sort) {
		List<Zone> zones = zonedao.getZones(start,limit,page,sort);
		return zones;
	}
	
	@Override
	public int getZonesCount() {
		List<Zone> zones = zonedao.getZones(0,60000,1,null);
		return zones.size();
	}

	@Override
	public boolean isExist(String zone_no) {
		
		return zonedao.isExist(zone_no);
	}

	@Override
	public boolean addZone(Zone zone) {
		zone.setCreate_date(new Timestamp(System.currentTimeMillis()));
		zonedao.addZone(zone);
		return true;
	}

	@Override
	public boolean updateZone(Zone zone) {
		zone.setUpdata_date(new Timestamp(System.currentTimeMillis()));
		zonedao.updateZone(zone);
		return true;
	}

	@Override
	public List<ZoneOpt> getZonesOpts() {
		List<Zone> zones = zonedao.getZonesOpts();
		List<ZoneOpt> results = new ArrayList<>();
		for(Zone zone:zones){
			ZoneOpt zoneOpt = new ZoneOpt();
			zoneOpt.setZone_name(zone.getZone_name());
			zoneOpt.setZone_no(zone.getZone_no());
			results.add(zoneOpt);
		}
		return results;
	}

	



}
